// statemanager.h : Defines a class for managing object oriented game states
// to control game flow
//$Id: StateManager.h 5 2009-07-27 17:33:21Z brwarner2 $

#pragma once

#include "ResourceManager.h"

using boost::any_cast;

class IGameState;

//Manages the states of a game
class CStateManager
{
public:
	CStateManager(void);
	~CStateManager(void);

	//Registers a new state with the engine
	bool RegisterState( const std::string &name, IGameState* pState );

	//Changes the currently active state (and whether to flush all states out)
	void ChangeState( const std::string &name, bool bFlush = false );

	//Pushes a state onto the state stack
	void PushState( const std::string &state );

	//Pops a state off the stack
	void PopState( void );

	//Calls the update function on all of the states
	void Update( float fElapsed, float fTotal );

	//Renders the states
	void Render( void );

	//Sends a message to a state
	void SendNotify( const std::string &state, const std::string msg, int nArg=0, const boost::any &pArg = 0);

	//Releases the object
	void Release( void );

private:
	//Map of names to states
	std::map< std::string, IGameState* > m_registeredStates;

	//Stack of the currently active states
	std::list< IGameState* > m_stateStack;

	//Information about the state that is going to be changed to next
	IGameState *m_pNextState;
	std::string m_nextStateName;
	bool m_bFlush;

	//State that is going to be pushed next cycle
	IGameState *m_pPushState;
	std::string m_pushStateName;

	//If we are going to pop next cycle
	bool m_bPop;
};
